/* @(#)GSOperatorProcessor.java    
 *
 * Project: BUS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li     2006-2-9    建立
 *   Jenny Li     2006-3-8   添加方法modifyPwd
 *   Jenny Li     2006-3-10  添加方法addOperator,modOperator,getOpersByOptForManage,getQuerySqlForManage
 *   Simonyi Peng 2006-3-10  添加方法setOperatorFunc,queryOperator,getQuerySql
 *   Jenny Li     2006-4-2   修改方法modOperatorPwd，添加加密处理,关闭Connection
 *   Jenny Li     2006-4-11  添加方法getViewableOrgAndOperator
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.business;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import com.hitrust.gs.bean.GSOperFunctionBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrganizationBean;
import com.hitrust.gs.dao.GSOperFunctionDAO;
import com.hitrust.gs.dao.GSOperatorDAO;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.service.GSBaseProcesser;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.util.security.Encryptor;

/**
 * 操作员业务逻辑处理类
 * 
 */
public class GSOperatorProcessor implements GSBaseProcesser{
    /**
     * 登陆系统
     * @param aGSOperatorBean   操作员数据对象
     * @return
     * @throws GSException
     */
    public GSOperatorBean loginSystem(GSOperatorBean aGSOperatorBean)
            throws GSException {
        GSOperatorBean tGSOperatorBean = null;
        GSOperatorDAO tGSOperatorDAO = new GSOperatorDAO();
        boolean tFlag = tGSOperatorDAO.isExist(aGSOperatorBean.getGs_oper_id());
        if (tFlag) {
            tGSOperatorBean = tGSOperatorDAO.queryOper(aGSOperatorBean);
            if(tGSOperatorBean == null){
                GSLogWriter.error(this,GSException.E10035_MSG);
                throw new GSException(GSException.E10035,GSException.E10035_MSG);
            }
        }else{
            GSLogWriter.error(this,GSException.E10034_MSG);
            throw new GSException(GSException.E10034,GSException.E10034_MSG);
        }
        return tGSOperatorBean;
    }
    /**
     * 取得登陆者功能权限
     * @param aOperId           操作员编码   
     * @return                  功能权限组
     * @throws GSException
     */
    public ArrayList getOperPrivilege(String aOperId)throws GSException{
        ArrayList tRs = new ArrayList();
        GSOperFunctionDAO tGSOperFunctionDAO = new GSOperFunctionDAO();
        ArrayList tList = tGSOperFunctionDAO.queryFunction(aOperId);
        if(tList.size() > 0){
            
            for(int i=0; i < tList.size(); i++){
                GSOperFunctionBean tGSOperFunctionBean = (GSOperFunctionBean)tList.get(i);
                if(tGSOperFunctionBean.getGs_oper_validity().equals("0")){
                    tRs.add(tGSOperFunctionBean.getGs_func_id());
                }
            }
        }
        return tRs;
    }
    /**
     * 取得符合查询条件的所有操作员
     * @param aBean             操作员数据对象
     * @return                  ResultProcess对象（用作分页处理）
     * @throws GSException
     */
    public ResultProcess getOperatorsByOpt(GSOperatorBean aBean,GSOperatorBean aCurOperBean) throws GSException{
        ArrayList tList = new ArrayList();
        ArrayList tRsList = new ArrayList();
        ResultProcess tProc = new ResultProcess();
        try{
            GSOperatorDAO tGSOperatorDAO = new GSOperatorDAO();
            String tSql = this.getQuerySql(aBean,aCurOperBean);
//            tList = tGSOperatorDAO.queryOperByOpt(aBean);
            tList = tGSOperatorDAO.queryOperBySql(tSql);
            String[] tRs = null;
            if(tList.size() > 0){
                for(int i=0; i<tList.size(); i++){
                    tRs = new String[9];
                    GSOperatorBean tGSOperatorBean = (GSOperatorBean)tList.get(i);
                    tRs[0] = tGSOperatorBean.getGs_oper_id();
                    tRs[1] = tGSOperatorBean.getGs_oper_name();
//                    tRs[2] = GSBaseManager.getOperatorRole(tGSOperatorBean.getGs_oper_level());
                    tRs[2] = tGSOperatorBean.getGs_oper_position();
                    tRs[3] = tGSOperatorBean.getGs_oper_phone();
                    tRs[4] = tGSOperatorBean.getGs_oper_email();
                    tRs[5] = GSBaseManager.getOrgNameByOrgId(tGSOperatorBean.getGs_oper_org_id());
                    tRs[6] = GSBaseManager.getValidityName(tGSOperatorBean.getGs_oper_validity());
                    tRs[7] = GSBaseManager.getSexName(tGSOperatorBean.getGs_oper_sex());
                    String pwd=Encryptor.decrypt(tGSOperatorBean.getGs_oper_pwd());
                    tRs[8] = pwd;
                    tRsList.add(tRs);
                }
            }
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10002,GSException.E10002_MSG);
        }
        tProc.setResult(tRsList);
        return tProc;
    }
    /**
     * 取得操作员浏览的查询SQL
     * @param aBean
     * @param aCurOperBean
     * @return
     */
    private String getQuerySql(GSOperatorBean aBean,GSOperatorBean aCurOperBean){
        StringBuffer tSql = new StringBuffer("select * from GS_OPERATOR");
        try{
            if(aBean.getGs_oper_id().equals("0000") && aBean.getGs_oper_org_id().equals("00000") && aBean.getGs_oper_name().equals("0000")){
                tSql.append(" where GS_OPER_ORG_ID<>'superadmin' and GS_OPER_ORG_ID in(");
                GSOrgProcessor tGSOrgProc = new GSOrgProcessor();
                ArrayList tOrgList = tGSOrgProc.getOperOrgAndSubOrg(aCurOperBean.getGs_oper_org_id());
                for(int i=0; i<tOrgList.size(); i++){
                   GSOrganizationBean tGSOrg = (GSOrganizationBean)tOrgList.get(i);
                   if(i == tOrgList.size() - 1)
                       tSql.append("'" + tGSOrg.getGs_org_id() + "')");
                   else
                       tSql.append("'" + tGSOrg.getGs_org_id() + "',");
                   
                }
            }else{
                if(!aBean.getGs_oper_id().equals("0000")){
                    tSql.append(" where GS_OPER_ID like '%"+aBean.getGs_oper_id() + "%' ");
                }else{
                    tSql.append(" where GS_OPER_ID like '%' ");
                }
                if(!aBean.getGs_oper_name().equals("0000")){
                    tSql.append("and GS_OPER_NAME like '%" + aBean.getGs_oper_name() + "%' ");
                }else{
                    tSql.append("and GS_OPER_NAME like '%' ");
                }
                if(!aBean.getGs_oper_org_id().equals("00000")){
                    tSql.append("and GS_OPER_ORG_ID like '%" + aBean.getGs_oper_org_id() + "%' ");
                }else{
                    tSql.append("and GS_OPER_ORG_ID like '%' ");
                }
            }
            
            if(!aBean.getGs_key_word().equalsIgnoreCase(""))
            {
            	tSql.append(" and ((GS_OPER_ID like '%"+aBean.getGs_key_word()+"%') or (GS_OPER_NAME like '%"+aBean.getGs_key_word()+"%') or (GS_OPER_position like '%"+aBean.getGs_key_word()+"%') ) ");
            }
            GSLogWriter.debug("SQL=" + tSql.toString());
            return tSql.toString();
            
        }catch(Exception e){
            e.printStackTrace();
        }
        return tSql.toString();
        
    }
    /**
     * 检测操作员是否有订单录入/审核身份
     * @param operId
     * @return boolean
     * @throws GSException
     */
    public boolean[] getModifyPrivilege(String operId) throws GSException {
        GSOperFunctionDAO opfd = new GSOperFunctionDAO();
        ArrayList ary = opfd.queryFunction(operId);
        boolean isRecoder = false;
        boolean isAuthorizer = false;
        for(int i=0;i<ary.size();i++){
            GSOperFunctionBean bean = (GSOperFunctionBean)ary.get(i);
            if(bean.getGs_func_id().equals("1001") && bean.getGs_oper_validity().equals("0"))
                isRecoder = true;
        }
        boolean[] returnValue = new boolean[]{isRecoder,isAuthorizer};
        return returnValue;
    }
    public ArrayList getViewableOperByLoginOper(String aOperId,String aOperOrgId) throws GSException{
        
        ArrayList tList = new ArrayList();
        StringBuffer tSql = new StringBuffer("select * from GS_OPERATOR where GS_OPER_ORG_ID in(");
        
        try{
            //取得操作员所属企业及其所有下级企业
            GSOrgProcessor tGSOrgProc = new GSOrgProcessor();
            ArrayList tOrgList = tGSOrgProc.getOperOrgAndSubOrg(aOperOrgId);
            for(int i=0; i<tOrgList.size(); i++){
               GSOrganizationBean tGSOrg = (GSOrganizationBean)tOrgList.get(i);
               if(i == tOrgList.size() - 1)
                   tSql.append("'" + tGSOrg.getGs_org_id() + "')");
               else
                   tSql.append("'" + tGSOrg.getGs_org_id() + "',");
               
            }
            GSOperatorDAO tOperDAO = new GSOperatorDAO();
            tList = tOperDAO.queryOperBySql(tSql.toString());
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10002,GSException.E10002_MSG);
        }
        return tList;
    }
    /**
     * 修改操作员密码
     * @param aOperatorBean     操作员封装Bean对象
     * @param aNewPwd           新密码
     * @return
     * @throws GSException
     */
    public boolean modifyPwd(GSOperatorBean aOperatorBean,String aNewPwd) throws GSException{
        boolean tFlag = false;
        GSOperatorDAO tOperatorDAO = new GSOperatorDAO();
        Connection tConn = null;
        try{
            tConn = tOperatorDAO.getConnetion();
            //判断用户是否存在且有效
            if(!tOperatorDAO.isExist(aOperatorBean.getGs_oper_id(),tConn)){
                GSLogWriter.error(this,GSException.E10034_MSG);
                throw new GSException(GSException.E10034,GSException.E10034_MSG);
            }
            //判断用户原密码是否正确
            GSOperatorBean tOperatorBean = tOperatorDAO.queryOper(aOperatorBean,tConn);
            if(tOperatorBean == null){
                GSLogWriter.debug(this,GSException.E10058_MSG);
                throw new GSException(GSException.E10058,GSException.E10058_MSG);
            }
            //修改密码
            tFlag = tOperatorDAO.modifyPwd(tConn,aOperatorBean.getGs_oper_id(),aNewPwd);
            
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E00001,GSException.E00001_MSG);
        }finally{
            GSOperatorDAO.close(tConn);
        }
        return tFlag;
    }
    /**
     * 查询可管理操作员新
     * @param aBean
     * @return
     * @throws GSException
     */
    public ResultProcess getOpersByOptForManage(GSOperatorBean aBean) throws GSException{
        ArrayList tList = new ArrayList();
        ArrayList tRsList = new ArrayList();
        ResultProcess tProc = new ResultProcess();
        try{
            GSOperatorDAO tGSOperatorDAO = new GSOperatorDAO();
            //取得查询SQL
            String tSql = this.getQuerySqlForManage(aBean);
            tList = tGSOperatorDAO.queryOperBySql(tSql);
            String[] tRs = null;
            if(tList.size() > 0){
                for(int i=0; i<tList.size(); i++){
                    //重新封装查询结果
                    tRs = new String[8];
                    GSOperatorBean tGSOperatorBean = (GSOperatorBean)tList.get(i);
                    tRs[0] = tGSOperatorBean.getGs_oper_id();
                    tRs[1] = tGSOperatorBean.getGs_oper_name();
//                    tRs[2] = GSBaseManager.getOperatorRole(tGSOperatorBean.getGs_oper_level());
                    tRs[2] = tGSOperatorBean.getGs_oper_position();//操作员职位
                    tRs[3] = tGSOperatorBean.getGs_oper_phone();
                    tRs[4] = tGSOperatorBean.getGs_oper_email();
                    tRs[5] = GSBaseManager.getOrgNameByOrgId(tGSOperatorBean.getGs_oper_org_id());
                    tRs[6] = GSBaseManager.getValidityName(tGSOperatorBean.getGs_oper_validity());
                    tRs[7] = GSBaseManager.getSexName(tGSOperatorBean.getGs_oper_sex());
                    tRsList.add(tRs);
                }
            }
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10002,GSException.E10002_MSG);
        }
        tProc.setResult(tRsList);
        return tProc;
    }
    /**
     * 取得操作员管理的查询SQL
     * @param aBean
     * @return
     */
    private String getQuerySqlForManage(GSOperatorBean aBean){
        StringBuffer tSql = new StringBuffer("select * from GS_OPERATOR");
        try{
            if(!aBean.getGs_oper_id().equals("0000")){
                tSql.append(" where GS_OPER_ID ='"+aBean.getGs_oper_id() + "' ");
            }else{
                tSql.append(" where GS_OPER_ID like '%' ");
            }
            if(!aBean.getGs_oper_name().equals("0000")){
                tSql.append("and GS_OPER_NAME ='" + aBean.getGs_oper_name() + "' ");
            }else{
                tSql.append("and GS_OPER_NAME like '%' ");
            }
            if(!aBean.getGs_oper_org_id().equals("00000")){
                tSql.append("and GS_OPER_ORG_ID ='" + aBean.getGs_oper_org_id() + "' ");
            }else{
                tSql.append("and GS_OPER_ORG_ID like '%' ");
            }
            
            //关键字查询
            if (aBean.getGs_key_word()!= null && !"".equalsIgnoreCase(aBean.getGs_key_word()))
            {
            	tSql.append(" and ((GS_OPER_ID like '%"+aBean.getGs_key_word()+"%') or (GS_OPER_NAME like '%"+aBean.getGs_key_word()+"%') or (GS_OPER_position like '%"+aBean.getGs_key_word()+"%') ) ");
            }
            

            
            tSql.append(" and GS_OPER_ORG_ID in (select gs_org_id from GS_ORGANIZATION) order by gs_oper_org_id ");
            GSLogWriter.debug("SQL=" + tSql.toString());
            return tSql.toString();
            
        }catch(Exception e){
            e.printStackTrace();
        }
        return tSql.toString();
        
    }
    /**
     * 新增操作员
     * @param aOperBean     操作员对象
     * @return
     * @throws GSException
     */
    public boolean addOperator(GSOperatorBean aOperBean) throws GSException{
        boolean tFlag = false;
        GSOperatorDAO tOperDAO = new GSOperatorDAO();
        try{
            tFlag = tOperDAO.isExist(aOperBean.getGs_oper_id());
            if(tFlag){
                GSLogWriter.error(this,GSException.E10059_MSG);
                throw new GSException(GSException.E10059,GSException.E10059_MSG);
            }else{
                String tCurDT = DateUtil.formateDateTime(DateUtil.getCurrentTime("DT","AD"));
                aOperBean.setGs_last_modify_dt(tCurDT);
                tFlag = tOperDAO.addOperator(aOperBean);
            }
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10060,GSException.E10060_MSG);
        }
        return tFlag;
    }
    /**
     * 修改操作员新
     * @param aOperBean     操作员对象
     * @return
     * @throws GSException
     */
    public boolean modOperator(GSOperatorBean aOperBean) throws GSException{
        boolean tFlag = false;
        GSOperatorDAO tOperDAO = new GSOperatorDAO();
        try{
            String tCurDT = DateUtil.formateDateTime(DateUtil.getCurrentTime("DT","AD"));
            aOperBean.setGs_last_modify_dt(tCurDT);
            tFlag = tOperDAO.modOperator(aOperBean);
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10060,GSException.E10060_MSG);
        }
        return tFlag;
    }
    
    
    /**
     * 为权限设置所定义的操作员查询方法
     * @param aBean
     * @return
     */
    public String getQuerySql(GSOperatorBean aBean){
        
        StringBuffer tSql = new StringBuffer("select a.gs_oper_id,a.gs_oper_name,a.gs_oper_position,b.gs_org_name from GS_OPERATOR a,GS_ORGANIZATION b ");
        try{
                if(aBean.getGs_oper_id()!= null && aBean.getGs_oper_id().length() != 0){
                    tSql.append(" where a.GS_OPER_ID like '%"+aBean.getGs_oper_id() + "%' ");
                }else{
                    tSql.append(" where 1=1 ");
                }
                if(aBean.getGs_oper_name() != null && aBean.getGs_oper_name().length() != 0){
                    tSql.append("and a.GS_OPER_NAME like '%" + aBean.getGs_oper_name() + "%' ");
                }else{
                    tSql.append("and 1=1 ");                    
                }
                if(aBean.getGs_oper_org_id() != null && aBean.getGs_oper_org_id().length() != 0){
                    tSql.append("and a.GS_OPER_ORG_ID like '%" + aBean.getGs_oper_org_id() + "%' ");
                }else{
                    tSql.append("and 1=1 ");
                }
                
                
			//关键字查询
			if (aBean.getGs_key_word()!= null &&!"".equalsIgnoreCase(aBean.getGs_key_word()))
			{
				tSql.append(" and ((GS_OPER_ID like '%"+aBean.getGs_key_word()+"%') or (GS_OPER_NAME like '%"+aBean.getGs_key_word()+"%') or (GS_OPER_position like '%"+aBean.getGs_key_word()+"%') ) ");
			}
			
			
            tSql.append(" and a.gs_oper_org_id = b.gs_org_id and a.gs_oper_validity = 0");
            GSLogWriter.debug("SQL=" + tSql.toString());
            return tSql.toString();
            
        }catch(Exception e){
            e.printStackTrace();
        }
        return tSql.toString();
        
    }

    /**
     * 为操作员管理所定义的操作员查询方法
     * @param aBean
     * @return
     */
    public String getQuerySqlWithPwd(GSOperatorBean aBean){
        
        StringBuffer tSql = new StringBuffer("select a.gs_oper_id,a.gs_oper_name,b.gs_org_name,a.gs_oper_pwd from GS_OPERATOR a,GS_ORGANIZATION b ");
        try{
                if(!aBean.getGs_oper_id().equals("0000")){
                    tSql.append(" where a.GS_OPER_ID like '%"+aBean.getGs_oper_id() + "%' ");
                }else{
                    tSql.append(" where 1=1 ");
                }
                if(!aBean.getGs_oper_name().equals("0000")){
                    tSql.append("and a.GS_OPER_NAME like '%" + aBean.getGs_oper_name() + "%' ");
                }else{
                    tSql.append("and 1=1 ");                    
                }
                if(!aBean.getGs_oper_org_id().equals("00000")){
                    tSql.append("and a.GS_OPER_ORG_ID like '%" + aBean.getGs_oper_org_id() + "%' ");
                }else{
                    tSql.append("and 1=1 ");
                }

            tSql.append(" and a.gs_oper_org_id = b.gs_org_id and a.gs_oper_validity = 0");
            GSLogWriter.debug("SQL=" + tSql.toString());
            return tSql.toString();
            
        }catch(Exception e){
            e.printStackTrace();
        }
        return tSql.toString();
        
    }

    /**
     * 查询操作员id，name，职务，所属机构
     * @param aBean
     * @return
     * @throws GSException
     */
    public ArrayList queryOperator(GSOperatorBean aBean) throws GSException { 
        GSOperatorDAO dao = new GSOperatorDAO();
        Connection conn = null;
        ArrayList ary  = new ArrayList();
        try{
            conn = dao.getConnetion();
            ResultSet rs = conn.prepareStatement(this.getQuerySql(aBean)).executeQuery();	
            if(rs!=null){
                while(rs.next()){
					String[] temp = new String[]{rs.getString(1).trim(),rs.getString(2).trim(),rs.getString(3) ==null ? "": rs.getString(3).trim(),rs.getString(4).trim()};
                    ary.add(temp);
                }
            }
        }catch(Exception e){
            throw new GSException (GSException.E10002,GSException.E10002_MSG);
        }finally{
            GSOperatorDAO.close(conn);
        }
        
        return ary;
        
    }

    /**
     * 查询操作员id，name，机构，pwd
     * @param aBean
     * @return
     * @throws GSException
     */
    public ArrayList queryOperatorWithPwd(GSOperatorBean aBean) throws GSException { 
        GSOperatorDAO dao = new GSOperatorDAO();
        Connection conn = null;
        ArrayList ary  = new ArrayList();
        try{
            conn = dao.getConnetion();
            ResultSet rs = conn.prepareStatement(this.getQuerySqlWithPwd(aBean)).executeQuery();
            if(rs!=null){
                while(rs.next()){
                    String[] temp = new String[]{rs.getString(1).trim(),rs.getString(2).trim(),rs.getString(3).trim(),Encryptor.decrypt(rs.getString(4).trim())};
                    ary.add(temp);
                }
            }
        }catch(Exception e){
            throw new GSException (GSException.E10002,GSException.E10002_MSG);
        }finally{
            GSOperatorDAO.close(conn);
        }
        
        return ary;
        
    }
    
    /**
     * 设置操作员权限
     * @param operId
     * @param strs1
     * @param strs2
     * @param aBean
     * @throws GSException
     */
    public void setOperatorFunc(String operId,String[] strs1,String[] strs2,GSOperatorBean aBean) throws GSException {
        String sql1 = "delete from gs_oper_function where gs_oper_id='"+operId+"'";
        String sql2 = "insert into gs_oper_function (gs_oper_id,gs_func_id,gs_oper_validity) values ('"+operId+"',?,0)";
        GSOperatorDAO dao = new GSOperatorDAO();
        Connection conn = null;
        try{
            conn = dao.getConnetion();
            conn.setAutoCommit(false);
            
            PreparedStatement pstmt1 = conn.prepareStatement(sql1);
            pstmt1.executeUpdate();
            pstmt1.close();
            
            PreparedStatement pstmt2 = conn.prepareStatement(sql2);
            if(strs1!=null){
                for(int i=0;i<strs1.length;i++){
                    pstmt2.setString(1,strs1[i]);
                    pstmt2.addBatch();
                }
            }
            if(strs2!=null){
                for(int i=0;i<strs2.length;i++){
                    pstmt2.setString(1,strs2[i]);
                    pstmt2.addBatch();                
                }
            }
            pstmt2.executeBatch();
            pstmt2.close();
            
            conn.commit();
            
        }catch(Exception ex){
            try{
                conn.rollback();
            }catch(Exception e1){}
            throw new GSException(GSException.E17791,GSException.E17791_MSG);
        }finally{
            try{
                conn.setAutoCommit(true);
            }catch(Exception e2){}
            GSOperatorDAO.close(conn);
        }
    }    
    
    
    /**
     * 超级管理员修改操作员密码
     * @param aOperBean     操作员对象
     * @return
     * @throws GSException
     */
    public boolean modOperatorPwd(String operId,String pwd) throws GSException{
        boolean tFlag = false;
        GSOperatorDAO tOperatorDAO = new GSOperatorDAO();
        Connection tConn = null;
        try{
            tConn = tOperatorDAO.getConnetion();
            //判断用户是否存在且有效
            if(!tOperatorDAO.isExist(operId,tConn)){
                GSLogWriter.error(this,GSException.E10034_MSG);
                throw new GSException(GSException.E10034,GSException.E10034_MSG);
            }           
            String tCurDT = DateUtil.formateDateTime(DateUtil.getCurrentTime("DT","AD"));
            //修改密码
            tFlag = tOperatorDAO.modOperatorPwd(tConn,operId,pwd,tCurDT);
        }catch(GSException ge){
            throw ge;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10060,GSException.E10060_MSG);
        }finally{
            GSOperatorDAO.close(tConn);
        }
        return tFlag;
    }
    /**
     * 检查用户是否有操作权限
     * @param aFunCode          功能代码
     * @param aOper             操作员
     * @return
     */
    public static boolean checkRights(String aFunCode,GSOperatorBean aOper){
        ArrayList tList = aOper.getOperatorRights();
        for(int i=0; i<tList.size(); i++){
            String temp = (String)tList.get(i);
            if(temp.equals(aFunCode)){
                return true;
            }
        }
        return false;
    }
    /**
     * 取得可操作的组织及组织所有的操作员关系集
     * @param aOper                 操作员对象
     * @return
     * @throws GSException
     */
    public static HashMap getViewableOrgAndOperator(GSOperatorBean aOper) throws GSException{
        HashMap tMap = new HashMap();
        
        GSOrgProcessor tOrgProc = new GSOrgProcessor();
        //取得当前操作员所属组织及该组织的下级组织
        ArrayList tList = tOrgProc.getOperOrgAndSubOrg(aOper.getGs_oper_org_id());
        tMap.put("organization",tList);
        if(tList.size() > 0){
            GSOperatorDAO tOperDAO = new GSOperatorDAO();
            for(int i=0; i<tList.size();i++){
                GSOrganizationBean tOrgBean = (GSOrganizationBean)tList.get(i);
                String tSql = "select * from GS_OPERATOR where gs_oper_id <>'superadmin' and GS_OPER_ORG_ID = '" + tOrgBean.getGs_org_id() + "'";
                //查询该组织所有的操作员
                ArrayList tList2 = tOperDAO.queryOperBySql(tSql);
                if(tList2.size() > 0){
                    tMap.put(tOrgBean.getGs_org_id(),tList2);
                }
            }
        }
        return tMap;
    }
    
    // add by Jackey start
    /**
     * 返回操作员的名称
     *
     * @param aOperId                 操作员ID
     * @return
     * @throws GSException
     * 
     */
    public static String getOperatorName(String aOperId) throws GSException
    {
    	String val = "";
    	
		GSOperatorDAO dao = new GSOperatorDAO();
		Connection conn = null;
		
		GSOperatorBean aBean = new GSOperatorBean();
		
		try{
			conn = dao.getConnetion();
			String sql = "select a.gs_oper_id,a.gs_oper_name from gs_operator a where a.gs_oper_id='"+aOperId+"'";
			ResultSet rs = conn.prepareStatement(sql).executeQuery();
			if(rs!=null){
				while(rs.next()){
					val = rs.getString(2).trim();
				}
			}
			else
			{
				val = aOperId;
			}
			if (rs != null) rs.close();
		}catch(Exception e){
			throw new GSException (GSException.E10002,GSException.E10002_MSG);
		}finally{
			GSOperatorDAO.close(conn);
		}
			
    	return val;
    }
    // add by Jackey end
}
